package bTree.LeetCode;

import java.util.LinkedList;
import java.util.Queue;

public class 统计参与通信的服务器 {
    public int countServers(int[][] grid) {
        int cnt=0;
        int row = grid.length;
        int line = grid[0].length;
        for (int i=0;i<row;i++){
            for (int j=0;j<line;j++){
                if (grid[i][j]==1){
                  cnt+=isOn(grid,i,j);
                }
            }
        }
        return cnt;
    }

    private int isOn(int[][] grid, int i, int j) {
        for (int line=0;line<grid[0].length;line++){
            if (grid[i][line]==1&&line!=j){
                return 1;
            }
        }
        for (int row=0;row<grid.length;row++){
            if (grid[row][j]==1&&row!=i){
                return 1;
            }
        }
        return 0;
    }
}